/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.cacheplugins  
 */
package com.apache.bid.service.cacheplugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.BidCommonUtil;
import com.apache.bid.common.Constant;
import com.apache.bid.common.WbdToolsUtil;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.common.cache.BidDataBaseRunable;
import com.apache.bid.entity.BidItemPrice;
import com.apache.bid.service.plugins.UnityItemPluginHelper;
import com.apache.cache.util.Validator;
import com.apache.tools.DateUtils.FmtStr;

/**
 * description:  修改过程信息
 * @author Hou Dayu 创建时间：2016-3-28  
 * 
 */
public class EditItemPricePluginImpl implements PluginConnector {

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		BidItemPrice price = new BidItemPrice();
		price = (BidItemPrice) WbdToolsUtil.getInstance().convert2Bean(param.getParams(), price);
		ResultEntity entity = new ResultEntity();
		if (Validator.isNull(price.getItemId())) {
			entity.setResult("false");
			entity.setMessage("缺少方法参数,方法执行失败");
		} else {
			String objId = String.valueOf(param.getParams("syncObjId"));
			Constant.getInstance().setJingjiaMap(objId, objId);
			final String key = Constant.getInstance().getJingjiaMap(objId);
			BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("itemPrice");
			synchronized (key) {
				BidItemPrice cacheVo = (BidItemPrice) cache.getCacheObjectByKey(cache.item_price_prefix
						+ price.getItemId());
				long fbtimeOld = BidCommonUtil.getMillTime(cacheVo.getCloseTime(), FmtStr.yyyyMMdd_HHmmss.toString());
				long fbtime = BidCommonUtil.getMillTime(price.getCloseTime(), FmtStr.yyyyMMdd_HHmmss.toString());
				if (fbtimeOld < fbtime) {
					cache.updateCacheObject(price);
					ParamsVo<BidItemPrice> priceVo = new ParamsVo<BidItemPrice>();
					priceVo.setObj(price);
					BidDataBaseRunable runable2 = new BidDataBaseRunable(priceVo, "bidItemPriceManager", "update");
					BidCacheFactory.getInstance().exeDatabase(runable2);
					String itemStop = Validator.getDefaultStr(String.valueOf(param.getParams("itemStop")), "F");
					if ("T".equals(itemStop)) {
						UnityItemPluginHelper.getInstance().stopItem(price.getItemId());
					}
				}
			}
			entity.setResult("true");
			entity.setMessage("修改成功");
			entity.setEntity("true");
		}
		return entity;
	}

}
